package model

import (
	"poker/comm"
	"poker/pb/proto/common"

	"go.mongodb.org/mongo-driver/bson/primitive"
)

type LogEvent int32
type LogType int32

const (
	LOG_EVENT_ITEMCHANGE LogEvent = 1
	LOG_EVENT_CURRCHANGE LogEvent = 2
	LOG_EVENT_TICKCHANGE LogEvent = 3
)

const (
	LOG_TYPE_ITEMAPPEDN = iota + 1
	LOG_TYPE_ITEMCONSUME
)

type ItemChange struct {
	ItemType comm.ItemTy `bson:"item_type" json:"item_type"`
	Name     string      `bson:"name" json:"name"`
	ItemId   int32       `bson:"item_id" json:"item_id"`
	Current  float64     `bson:"current" json:"current"`
	Change   float64     `bson:"change" json:"change"`
}

type WrongData struct {
	ItemId  int32
	Current float64
	Should  float64
}

//go:generate mongo-dao-generator -model-dir=. -model-names=Logs -dao-dir=../../dao/logs
type Logs struct {
	ID         primitive.ObjectID `bson:"_id" gen:"autoFill"`
	UID        int64              `bson:"uid"`
	Event      LogEvent           `bson:"event"`
	Type       LogType            `bson:"type"`
	Extra      string             `bson:"extra"` // 额外补充信息
	Reason     int32              `bson:"reason"`
	Info       []ItemChange       `bson:"info"`
	WrongDatas []WrongData        `bson:"wrong_datas"`

	CTime primitive.DateTime `bson:"CTime"`
}

//go:generate mongo-dao-generator -model-dir=. -model-names=DiamondLogs -dao-dir=../../dao/diamondLogs
type DiamondLogs struct {
	ID     primitive.ObjectID `bson:"_id" gen:"autoFill"`
	UID    int64              `bson:"uid"`
	Cost   int64              `bson:"cost"`
	Reward []ItemChange       `bson:"reward"`
	Extra  string             `bson:"extra"` // 额外补充信息
	Reason int32              `bson:"reason"`
	CTime  primitive.DateTime `bson:"CTime"`
}

//go:generate mongo-dao-generator -model-dir=. -model-names=ShopGoodsLogs -dao-dir=../../dao/shopGoodsLogs
type ShopGoodsLogs struct {
	ID      primitive.ObjectID `bson:"_id" gen:"autoFill"`
	UID     int64              `bson:"uid"`
	GoodsId int32              `bson:"goods_id"`
	Cost    common.Item        `bson:"cost"`
	Reward  []common.Item      `bson:"reward"`
	Extra   string             `bson:"extra"` // 额外补充信息
	Reason  int32              `bson:"reason"`
	CTime   primitive.DateTime `bson:"CTime"`
}

type Logout struct {
	UID  int64
	CID  int64
	Time int64
}

//go:generate mongo-dao-generator -model-dir=. -model-names=LoginLogs -dao-dir=../../dao/loginLogs
type LoginLogs struct {
	ID            primitive.ObjectID  `bson:"_id" gen:"autoFill"`
	UID           int64               `bson:"uid"`
	CID           int64               `bson:"cid"`
	Device        string              `bson:"device"`
	DeviceId      string              `bson:"device_id"`
	Platform      string              `bson:"platform"` // 平台 android ios web miniWechat
	Channel       int32               `bson:"channel"`  // 登录渠道
	LoginIP       string              `bson:"login_ip"`
	LoginTime     primitive.DateTime  `bson:"login_time"`
	LastLoginTime primitive.DateTime  `bson:"last_login_time"`
	LogoutTime    *primitive.DateTime `bson:"logout_time"`
	OnlineTime    int64               `bson:"online_time"`
	IsComeback    bool                `bson:"is_comeback"` // 是否是回流用户
}

//go:generate mongo-dao-generator -model-dir=. -model-names=RedeemLogs -dao-dir=../../dao/redeemLogs
type RedeemLogs struct {
	ID       primitive.ObjectID `bson:"_id" gen:"autoFill"`
	UID      int64              `bson:"uid"`
	Mobile   string             `bson:"mobile"`
	Nickname string             `bson:"nickname"`
	Count    float64            `bson:"count"`
	Message  string             `bson:"message"`
	CTime    primitive.DateTime `bson:"CTime" gen:"autoFill"`
}
